var app = new Vue({
    el: '.app',
    data() {
        return {
            isindex: 1,
            istest: "",
            faucettext: '',
            faucetnum: 0,
            showfaucet:Boolean,
            isshowlanguage:false,
            flag:false
        }
    },
    created() {
        let hret = window.location.pathname.split('/')
        var test = window.location.href;
        let hret3 = hret[2]
        let that = this
        if (document.getElementsByClassName('Thereare')[0] == undefined) {
            this.faucettext = ""
            this.showfaucet = false 
        } else {
            let LastTime = document.getElementsByClassName('lastFauce')[0].value
            if (LastTime == "") {
                this.faucettext = ""
                this.showfaucet = false 
            } else {
                this.FreeFaucet()
            }
        }
        this.setRem(27)
        if(window.location.pathname=='/m'){
            this.isindex = 1
        }else if(window.location.pathname=='/m/growth'){
            this.isindex = 2
        }else if(window.location.pathname=='/m/personal'){
            this.isindex = 3
        }
        else if(window.location.pathname=='/m/announcement'){
            this.isindex = 5
        }
        else if(window.location.pathname=='/m/Promotionpage'){
            this.isindex = 6
        }else if(window.location.pathname.indexOf('/m/promotiondetail')==0){
            this.isindex = 6
        }else if(window.location.pathname.indexOf('/m/Details')==0){
            this.isindex = 5
        }else if(window.location.pathname.indexOf('/m/deposit')==0){
            this.isindex = 2
        }else if(window.location.pathname.indexOf('/m/withdraw')==0){
            this.isindex = 2
        }
        else if(window.location.pathname.indexOf('/m/transfer')==0){
            this.isindex = 2
        }
    },
    methods: {
        Menuselected(index) {
            this.isindex = index
        },
        slidewqesadsa() {
            document.getElementsByClassName("sidebar")[0].style.right = 0
            $(".Mask").fadeIn(1000)
        },
        closeslide() {
            document.getElementsByClassName("sidebar")[0].style.right = "-100%"
            $(".Mask").fadeOut(1000)
        },
        mask() {
            document.getElementsByClassName("sidebar")[0].style.right = "-100%"
            $(".Mask").fadeOut(1000)
        },
        setRem(itemNum) { //设置字体rem
            let size = itemNum || 36;
            window.onresize = remSize;
            remSize();
            function remSize() {
                let html = document.getElementsByTagName('html')[0], w = html.clientWidth;
                w = w > 768 ? 768 : w;
                html.style.fontSize = w / size + 'px'
            }
        },
        chooselanguage(lang, defaultlang) { //选择语言
            if (lang === defaultlang) { //默认语言
                return
            }
            let params = {
                lang: lang
            }
            axios.post('/user/setlanguage', params).then((res) => {
                if (res.data.code == 200) {
                    location.reload()
                }
            })
        },
        FreeFaucet() {
            let FAUCE = document.getElementsByClassName('lastFauce')[0].value || 0
            if (FAUCE) {
                let timer = new Date().getTime()
                let countdown = timer - FAUCE
                // - 8 * 60 * 60 * 1000
                let lastTime = 24 * 60 * 60 * 1000 - countdown
                if (countdown > 24 * 60 * 60 * 1000) {
                    this.faucettext = ""
                    this.showfaucet = false 
                    return
                }
                let obj = {
                    h: null,
                    m: null,
                    s: null
                };
                obj.h = Math.floor(lastTime / 1000 / 60 / 60);
                obj.m = parseInt((lastTime / 1000 / 60) % 60, 10);
                obj.s = parseInt((lastTime / 1000) % 60, 10);
                let timelast = setInterval(() => {
                    obj.s--
                    if (obj.s < 0) {
                        --obj.m;
                        obj.s = 59;
                    }
                    if (obj.m < 0) {
                        --obj.h;
                        obj.m = 59;
                    }
                    if (obj.h < 0) {
                        obj.s = 0;
                        obj.h = 0;
                        obj.m = 0;
                    }
                    function charLeftAll(n) {
                        if (n < 10) return "0" + n;
                        else return n;
                    }
                    this.faucettext = charLeftAll(obj.h) +
                        ":" +
                        charLeftAll(obj.m) +
                        ":" +
                        charLeftAll(obj.s)
                    if (obj.s == 0 && obj.h == 0 && obj.m == 0) {
                        this.faucettext = ""
                        this.showfaucet = false 
                        clearInterval(timelast)
                    }
                }, 1000);
                return
            }
        },
        FreeFaucetone() {
            if (this.faucettext == "") {
                this.showfaucet = true
                this.faucetnum = 1
                if (this.faucetnum == 1) {
                    setTimeout(() => {
                        this.faucetnum = 0
                    }, 2000)
                }
                axios.post("/adress/coin/faucet").then(res => {
                    if (res.data.data != undefined) {
                        let obj = {
                            h: null,
                            m: null,
                            s: null
                        };
                        obj.h = 23
                        obj.m = 59
                        obj.s = 60
                        let timelast = setInterval(() => {
                            obj.s--
                            if (obj.s < 0) {
                                --obj.m;
                                obj.s = 59;
                            }
                            if (obj.m < 0) {
                                --obj.h;
                                obj.m = 59;
                            }
                            if (obj.h < 0) {
                                obj.s = 0;
                                obj.h = 0;
                                obj.m = 0;
                            }
                            function charLeftAll(n) {
                                if (n < 10) return "0" + n;
                                else return n;
                            }
                            this.faucettext = charLeftAll(obj.h) +
                                ":" +
                                charLeftAll(obj.m) +
                                ":" +
                                charLeftAll(obj.s)
                        }, 1000);
                    } else {

                    }
                });
            } else {

            }
        }
    }
})